package com.ljl.ningwei.common.utils;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author 吕佳乐
 * @version 1.0
 * @date 2025-03-14 10:19
 */
public class TimeUtil {
    public static Integer getTime(){
        long millisTimestamp = System.currentTimeMillis();

        // 转换为秒级时间戳
        int secondsTime = (int) (millisTimestamp / 1000);
        return secondsTime;
    }

    public static String formatTime(Integer secondsTimestamp) {
        // 将秒级时间戳转换为毫秒级
        long millisTimestamp = secondsTimestamp * 1000L;
        // 创建日期对象
        Date date = new Date(millisTimestamp);
        // 定义日期格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 格式化日期
        return sdf.format(date);
    }

    public static void main(String[] args) {
        Integer timestamp = getTime();
        System.out.println("时间戳: " + timestamp);
        System.out.println("格式化时间: " + formatTime(timestamp));
    }
}
